import { TrainingAnalytics } from "../Analytics/TrainingAnalytics";
import { GrpcExtensions } from "../Communicator/GrpcExtensions";
import { Guid } from "../Utils/Guid";
import pb from "../Grpc/CommunicatorObjects/pb.js";
import { IncomingMessage } from "./InComingMessage";
import { SideChannel } from "./SideChannel";
export class TrainingAnalyticsSideChannel extends SideChannel {
    private static readonly k_TrainingAnalyticsConfigId: string = "b664a4a9-d86f-5a5f-95cb-e8353a7e8356";

    constructor() {
        super();
        this.channelId = new Guid(TrainingAnalyticsSideChannel.k_TrainingAnalyticsConfigId);
    }

    onMessageReceived(msg: IncomingMessage): void {
        let anyMessage: pb.communicator_objects.TrainingEnvironmentInitialized | pb.communicator_objects.TrainingBehaviorInitialized = null!;
        anyMessage = pb.communicator_objects.TrainingEnvironmentInitialized.decode(msg.getRawBytes());
        if (anyMessage) {
            const envInitEvent = GrpcExtensions.toTrainingEnvironmentInitializedEvent(anyMessage);
            TrainingAnalytics.trainingEnvironmentInitialized(envInitEvent);
        } else {
            anyMessage = pb.communicator_objects.TrainingBehaviorInitialized.decode(msg.getRawBytes());
            if (anyMessage) {
                const behaviorTrainingEvent = GrpcExtensions.toTrainingBehaviorInitializedEvent(anyMessage);
                TrainingAnalytics.trainingBehaviorInitialized(behaviorTrainingEvent);
            }
        }
    }
}